package com.woniuxy.yogaapp.handler;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.yogaapp.dto.IndexMes;
import com.woniuxy.yogaapp.mapper.ChatMapper;
import com.woniuxy.yogaapp.pojo.Chat;
import com.woniuxy.yogaapp.pojo.Indexmes;
import com.woniuxy.yogaapp.service.ChatService;
import com.woniuxy.yogaapp.service.CoachService;
import com.woniuxy.yogaapp.service.IndexmesService;
import com.woniuxy.yogaapp.service.YogaClubService;

import lombok.Data;

@Data
@Controller
@RequestMapping("/admin")
@Scope("prototype")
public class AdminHandler {

	@Resource
	private CoachService coachService;

	@Resource
	private YogaClubService yogaClubService;

	@Resource
	private IndexmesService indexmesService;
	@Resource
	private ChatService chatService;

	// 同意教练认证
	@RequestMapping("/agreecoach")
	@ResponseBody
	public String agreeCoach(Chat chat) {
		String result = coachService.agreeCoach(chat);
		return result;
	}

	// 拒绝教练认证
	@RequestMapping("/disagreecoach")
	@ResponseBody
	public String disagreeCoach(Chat chat) {
		String result = coachService.disagreeCoach(chat);
		return result;
	}

	// 同意场馆认证
	@RequestMapping("/agreeclub")
	@ResponseBody
	public String agreeYogaClub(Chat chat) {
		String result = yogaClubService.agreeYogaClub(chat);
		return result;
	}

	// 拒绝场馆认证
	@RequestMapping("/disagreeclub")
	@ResponseBody
	public String disagreeYogaClub(Chat chat) {
		String result = yogaClubService.disagreeYogaClub(chat);
		return result;
	}

	// 推送消息展示至管理员
	@RequestMapping("/sendindex")
	@ResponseBody
	public List<IndexMes> sendMesToIndex() {
		List<IndexMes> index = indexmesService.findAllIndexMes();
		return index;
	}

	// 推送消息至主页
	@RequestMapping("/sendtoindex")
	@ResponseBody
	public List<IndexMes> sendToIndex() {
		List<IndexMes> index = indexmesService.findIndexMes();
		return index;
	}

	// 新增推送消息
	@RequestMapping("/addindexmes")
	@ResponseBody
	public String addIndexmes(Indexmes indexmes) {
		String result = "新增失败";
		int row = indexmesService.addIndexmes(indexmes);
		if (row > 0) {
			result = "新增成功";
		}
		return result;
	}

	// 推送指定消息
	@RequestMapping("/sendmestoindex")
	@ResponseBody
	public String sendIndexmes(Indexmes indexmes) {
		String result = "推送失败";
		int row = indexmesService.sendIndexmes(indexmes);
		if (row > 0) {
			result = "推送成功";
		}
		return result;
	}

	// 取消推送消息
	@RequestMapping("/notsendmes")
	@ResponseBody
	public String notSendMes(Indexmes indexmes) {
		String result = "撤销失败";
		int row = indexmesService.notSendMes(indexmes);
		if (row > 0) {
			result = "撤销成功";
		}
		return result;
	}

	// 删除推送消息
	@RequestMapping("/delectindexmes")
	@ResponseBody
	public String delectIndexmes(Indexmes indexmes) {
		String result = "删除失败";
		int row = indexmesService.deleteIndexmes(indexmes);
		if (row > 0) {
			result = "删除成功";
		}
		return result;
	}

	// 展示未处理教练认证消息
	@RequestMapping("/showcoachmanage")
	@ResponseBody
	public List<Chat> showCoachManage() {
		List<Chat> chat = chatService.findAllCoachMes();
		return chat;
	}

	// 展示未处理场馆认证消息
	@RequestMapping("/showclubmanage")
	@ResponseBody
	public List<Chat> showClubManage() {
		List<Chat> chat = chatService.findAllClubMes();
		return chat;
	}

	// 展示已处理教练认证消息
	@RequestMapping("/showreadycoachmanage")
	@ResponseBody
	public List<Chat> showReadyCoachManage() {
		List<Chat> chat = chatService.findReadyCoachMes();
		return chat;
	}

	// 展示已处理场馆认证消息
	@RequestMapping("/showreadyclubmanage")
	@ResponseBody
	public List<Chat> showReadyClubManage() {
		List<Chat> chat = chatService.findReadyClubMes();
		return chat;
	}
}
